package com.rtrj.center.controller.user;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import com.rtrj.common.constant.ReturnMessage;
import com.rtrj.common.controller.BaseController;
import com.rtrj.resource.data.entity.user.UserEntity;
import com.rtrj.resource.logic.manager.user.UserManager;


@Controller
@RequestMapping(value="/userController")
public class UserController extends BaseController {

	private static final Logger logger = LoggerFactory.getLogger(UserController.class);
	
	@Autowired
	private UserManager userManager;
	
	@RequestMapping(value="/userListController")
	public String UserListController(@ModelAttribute("userEntity") UserEntity userEntity){
		logger.debug("user query list center controller begin");
		try{
			Map<Object, Object> map = userManager.UserListManager(userEntity);
			request.setAttribute("map", map);
			return "/html/index/index_list.jsp";
		}catch(Exception e){
			logger.error("user query list center controller end",e);
		}
		return ReturnMessage.ERROR_MSG;
	}
	
	@RequestMapping(value="/userLoginController")
	public String UserLoginController(@ModelAttribute("userEntity") UserEntity userEntity){
		logger.debug("user login center controller begin");
		try{
			String result = userManager.UserLoginManager(userEntity);
			if(ReturnMessage.SUCCESS.equals(result)){
				UserListController(userEntity);
			}
		}catch(Exception e){
			logger.error("user login center controller end",e);
		}
		return ReturnMessage.ERROR_MSG;
	}
}
